package com.bckj.fastboot.upms.biz.service;

import com.bckj.fastboot.upms.api.dto.ClientAuthInfo;
import com.bckj.fastboot.upms.biz.repository.SysOauthClientDetailsRepository;
import com.bckj.fastboot.upms.biz.convert.SysOauthClientDetailsConvert;
import com.bckj.fastboot.upms.api.vo.SysOauthClientDetailsVO;
import com.bckj.fastboot.upms.api.dto.SysOauthClientDetailsRequest;
import com.bckj.fastboot.upms.api.dto.SysOauthClientDetailsQuery;
import com.bckj.fastboot.upms.api.entity.SysOauthClientDetails;

import com.bckj.fastboot.core.lang.exception.BusinessException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户端信息表(SysOauthClientDetails)domain-service
 *
 * @author wfc
 * @since 2023-09-11 17:38:49
 */
@Service
@RequiredArgsConstructor
public class SysOauthClientDetailsService {

    private final SysOauthClientDetailsRepository sysOauthClientDetailsRepository;
	
    private final SysOauthClientDetailsConvert sysOauthClientDetailsConvert;
	
    /**
     * 列表
     *
     * @param query req
     * @return list
     */
    public List<SysOauthClientDetailsVO> list(SysOauthClientDetailsQuery query){
        return sysOauthClientDetailsRepository.getBaseMapper().list(query);
    }
    
     /**
     * 保存
     *
     * @param request req
     */
    public boolean save(SysOauthClientDetailsRequest request) {
        return sysOauthClientDetailsRepository.save(sysOauthClientDetailsConvert.request2Bean(request));
    }

    /**
     * 修改
     *
     * @param request req
     */
    public boolean update(SysOauthClientDetailsRequest request) {
        return sysOauthClientDetailsRepository.updateById(sysOauthClientDetailsConvert.request2Bean(request));
    }
    
    /**
     * 详情
     *
     * @param id id
     * @return vo
     */
    public SysOauthClientDetailsVO details(Long id) {
        SysOauthClientDetails bean = sysOauthClientDetailsRepository.getById(id);
        if (null == bean) {
            throw new BusinessException("当前对象不存在!");
        }
        return sysOauthClientDetailsConvert.bean2VO(bean);
    }
    
    /**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
    public boolean saveSysOauthClientDetails(SysOauthClientDetailsRequest request) {
        SysOauthClientDetails data = sysOauthClientDetailsConvert.request2Bean(request);
        return sysOauthClientDetailsRepository.save(data);
    }
    
    /**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	public boolean updateSysOauthClientDetails(SysOauthClientDetailsRequest request) {
        SysOauthClientDetails data = sysOauthClientDetailsConvert.request2Bean(request);
        return sysOauthClientDetailsRepository.updateById(data);
	}

	/**
	 * 根据Id移除
	 *
	 * @param id id
	 * @return boolean
	 */
	public boolean remove(Long id) {
        //TODO LIMIT
		return sysOauthClientDetailsRepository.removeById(id);
	}

    public ClientAuthInfo findByClientId(String clientId) {
        return sysOauthClientDetailsRepository.getBaseMapper().findByClientId(clientId);
    }
}

